package ar.edu.itba.it.pdc.commons;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class TimeConverter {

	private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy");
	private static final DateTimeFormatter fullfmt = DateTimeFormat.fullDate();// Fri, 20 May 2011 13:58:18 -0300
	private static final DateTimeFormatter headerFmt = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z");
	
	public static String printDateTime(DateTime time) {
		return fmt.print(time.getMillis());
	}
	
	public static DateTime parseDateTime(String dateTime) {
		return fmt.parseDateTime(dateTime);
	}
	
	public static DateTime parseFullDateTime(String fullDateTimeText) {
		return fullfmt.parseDateTime(fullDateTimeText);
	}
	
	public static String printFullDateTimeText(String fullDateTimeText) {
		return printDateTime(parseFullDateTime(fullDateTimeText));
	}
	
	public static DateTime parseDateHeaderTime(Header header) {
		return headerFmt.parseDateTime(header.getValue().trim());
	}
}
